package es.christiangarcia.android.pokepedia.model.db;

import android.database.sqlite.SQLiteDatabase;
import android.provider.BaseColumns;
import android.util.Log;

public class PokemonAttackHMTMTable implements BaseColumns {

	public static final String TABLE_NAME = "pokemon_attack_hm_tm";

	public static final String NUM_POKEMON_COLUMN = "num_pokemon";
	public static final String ID_HM_TM_COLUMN = "id_hm_tm";

	//@formatter:off
	public static final String[] ALL_COLUMNS = {
			_ID,
			NUM_POKEMON_COLUMN,
			ID_HM_TM_COLUMN,
	};
	public static final String DATABASE_CREATE = "CREATE TABLE " 
		+ TABLE_NAME
		+ " ("
		+ PokemonAttackHMTMTable._ID + " INTEGER PRIMARY KEY,"
		+ PokemonAttackHMTMTable.NUM_POKEMON_COLUMN + " INTEGER NOT NULL,"
		+ PokemonAttackHMTMTable.ID_HM_TM_COLUMN + " INTEGER NOT NULL,"
		+ "FOREIGN KEY(" + PokemonAttackHMTMTable.NUM_POKEMON_COLUMN + ") "
		+ "REFERENCES " + TABLE_NAME + "("+ PokemonTable._ID + " ON DELETE CASCADE"
		+ "FOREIGN KEY(" + PokemonAttackHMTMTable.ID_HM_TM_COLUMN + ") "
		+ "REFERENCES " + TABLE_NAME + "("+ HMTMTable._ID + " ON DELETE CASCADE"
		+ ");";
	// @formatter:on

	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		Log.w(PokemonAttackHMTMTable.class.getName(), "Upgrading database from version " + oldVersion + " to "
				+ newVersion + ", which will destroy all old data");
		database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(database);
	}
}